package com.scnu409.mimicontact;


import java.util.ArrayList;
import java.util.List;

import com.scnu409.Adapter.TabFragmentAdapter;
import com.scnu409.fragment.CommunityFragment.Callbacksd;
import com.scnu409.fragment.HistoryContentFragment.Callbacks;

import android.annotation.SuppressLint;
import android.app.ActionBar;
import android.app.ActionBar.Tab;
import android.app.Activity;
import android.app.FragmentTransaction;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Toast;



public class Home extends FragmentActivity implements Callbacks,Callbacksd{

	/*
	 *@param actionBar 
	 */
	ViewPager viewPager;

	List<TabDialog> list=new ArrayList<TabDialog>();
	
	@SuppressLint("NewApi") 
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_home);
		TabFragmentAdapter adapter;
		
		/*
		 * @param adapter home主页中的适配器
		 * @param viewPager 滑动的空间
		 */
		
		
		adapter=new TabFragmentAdapter(getSupportFragmentManager());
		viewPager=(ViewPager)findViewById(R.id.switcher);
		viewPager.setAdapter(adapter);
		viewPager.setOnPageChangeListener(new OnPageChangeListener(){

			@Override
			public void onPageScrollStateChanged(int arg0) {
			}

			@Override
			public void onPageScrolled(int arg0, float arg1, int arg2) {
			}

			@Override
			public void onPageSelected(int arg0) {
			}
			
		});
	}
	
	//初始化函数
	public void init() {
		TabDialog one =(TabDialog) findViewById(R.id.id_indicate_one);
		TabDialog two =(TabDialog) findViewById(R.id.id_indicate_two);
		TabDialog three =(TabDialog) findViewById(R.id.id_indicate_three);
		TabDialog four =(TabDialog) findViewById(R.id.id_indicate_four);
		
		list.add(one);
		list.add(two);
		list.add(three);
		list.add(four);
		
		one.setOnClickListener(clickListener);
		two.setOnClickListener(clickListener);
		three.setOnClickListener(clickListener);
		four.setOnClickListener(clickListener);
		
		one.setAlpha(1.0f);
	}
	
	OnClickListener clickListener=new OnClickListener(){@Override
		public void onClick(View v) {
		
		resetOtherTab();
		switch(v.getId())
		{
		//依次选择相应的tab，跳转到相应的fragment
		case R.id.id_indicate_one:
			list.get(0).setAlpha(1.0f);
			viewPager.setCurrentItem(0);
			break;
		case R.id.id_indicate_two:
			list.get(1).setAlpha(1.0f);
			viewPager.setCurrentItem(1);
			break;
		case R.id.id_indicate_three:
			list.get(2).setAlpha(1.0f);
			viewPager.setCurrentItem(2);
			break;
			
		case R.id.id_indicate_four:
			list.get(3).setAlpha(1.0f);
			viewPager.setCurrentItem(3,true);
			break;
			
		}
	}};
	

			@Override
			public void onItemSelected(Integer id) {
			}

			

			//重置其他为选中的tab
			public void resetOtherTab() {
				for(int i=0;i<list.size();i++)
				{
					//初始化使其他全部的icon和文本为透明
					list.get(i).setAlpha(0f);
				}
			}

}
